package com.chessimo.main;

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

public class Sound {

	private static String soundError = "sounds/error.wav";
	private static String soundOK = "sounds/ok.wav";
	private static String soundTime = "sounds/time.wav";
	private static String soundMove = "sounds/move.wav";

	public void play(String sType) throws UnsupportedAudioFileException,
			IOException, LineUnavailableException {
		
		if (Chess.conf.soundParam == 0) {
			return;
		}
		
		String selecSound = "";

		if (sType.equals("ERROR")) {
			selecSound = soundError;
		} else if (sType.equals("OK")) {
			selecSound = soundOK;
		} else if (sType.equals("TIME")) {
			selecSound = soundTime;
		} else {
			selecSound = soundMove;
		}

		File soundFile = new File(selecSound);
		AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);
		Clip clip = AudioSystem.getClip();
		clip.open(audioIn);
		clip.start();

	}

}
